//
//  M4HistoryOtherCell.swift
//  M4
//
//  Created by YuChuang on 2024/8/22.
//

import UIKit

class M4HistoryOtherCell: M4BaseTableViewCell {
    
    @IBOutlet weak var M4HistoryOtherLogo: UIImageView!
    
    @IBOutlet weak var M4HistoryOtherName: UILabel!
    
    @IBOutlet weak var M4HistoryOtherStatus: UILabel!
    
    @IBOutlet weak var M4HisLabel2: UILabel!
    
    @IBOutlet weak var M4HistoryOtherDate: UILabel!
    
    @IBOutlet weak var M4HistoryOtherAmount: UILabel!
    
    @IBOutlet weak var M4HisLabel3: UILabel!
    
    @IBOutlet weak var M4HistoryOtherDays: UILabel!
    
    @IBOutlet weak var M4HistoryCellButton: UIButton!
    
    
    private var hisModel: M4LoanOrderListModel?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func M4UpdateDataAndUI() {
        let model = data as? M4LoanOrderListModel
        hisModel = model
        M4HistoryOtherLogo.sd_setImage(with: URL(string: model?.UcddgfwSXM ?? ""))
        M4HistoryOtherName.text = model?.LcMnJMQqO
        let time = (model?.KYaDf ?? 0) / 1000
        let date = Date(timeIntervalSince1970: TimeInterval(time))
        let formatter = DateFormatter()
        formatter.dateFormat = "dd-MM-yyyy"
        let dateString = formatter.string(from: date)
        M4HistoryOtherDate.text = model?.UEKgEb ?? ""
        if model?.LlCrBfHzOES == 1 {//已结清
            M4HistoryOtherStatus.text = "Liquidado"
            M4HistoryOtherStatus.textColor = COLOR_666666
            M4HisLabel2.text = "Monto del pago"
            M4HistoryOtherAmount.text = "$\(M4String.M4BlankAmount(original: "\(model?.HQhxSZWP ?? 0)"))"
            M4HisLabel3.text = "Hora de pago"
            let time1 = (model?.CCTWZJSPfa ?? 0) / 1000
            let date1 = Date(timeIntervalSince1970: TimeInterval(time1))
            let dateString1 = formatter.string(from: date1)
            M4HistoryOtherDays.text = model?.GqU2cj ?? ""
            M4HistoryCellButton.isHidden = true
        }
        else {
            M4HistoryOtherStatus.text = "En trámite"
            M4HistoryOtherStatus.textColor = COLOR_00479D
            M4HisLabel2.text = "Monto del préstamo"
            M4HistoryOtherAmount.text = "$\(M4String.M4BlankAmount(original: "\(model?.Nsrzn ?? 0)"))"
            M4HisLabel3.text = "Días del préstamo"
            M4HistoryOtherDays.text = "\(model?.Xex ?? 0)Días"
            M4HistoryCellButton.isHidden = false
        }
    }
    
    override func M4CellTopEdge() -> CGFloat {
        return 10
    }
    
    @IBAction func M4HistoryCellAction(_ sender: UIButton) {
        M4CellActionDelegate?.M4CellAction(M4IDAction(actionType: M4HistoryRepayAction.M4HisCellAction.rawValue, actionData: hisModel))
        sender.M4EventUnavailable = false
    }
    
}
